/*
* coder: Dzlua
* email: 505544956@qq.com
* time : 2018-04-19 17:43
*/

#include "../helper.h"

int APIENTRY _tWinMain(HINSTANCE hInstance
    , HINSTANCE hPrevInstance
    , LPTSTR lpCmdLine
    , int nCmdShow )
{
    auto mgr = ui::CManager::init_instance();
    if (!mgr->Init(hInstance)) {
        print("Manager init error.");
        return 1;
    }

    {
        RECT rc = { 0, 0, 480, 640 };
        auto parent = ui::CWindow::instance();
        auto hwnd = parent->Create( 0 , rc
            , _T("ui window parent")
            , WS_VISIBLE | WS_POPUP | WS_THICKFRAME | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
            , WS_EX_APPWINDOW);
        if (hwnd) {
            parent->CenterWindow();
            parent->ShowWindow(nCmdShow);
            parent->UpdateWindow();
            mgr->AddWindow(_T("parent"), parent);
            mgr->SetMainWindow(parent);
        }
    }

    {
        RECT rc = { 0, 0, 480, 640 };
        auto child = ui::CWindow::instance();
        HWND hwndp = 0;
        auto parent = mgr->GetWindow(_T("parent"));
        if (parent) hwndp = parent->m_hWnd;
        auto hwnd = child->Create( hwndp , rc
            , _T("ui window child")
            , WS_VISIBLE | WS_POPUP | WS_THICKFRAME | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
            , WS_EX_APPWINDOW);
        if (hwnd) {
            child->CenterWindow();
            child->ShowWindow(nCmdShow);
            child->UpdateWindow();
            mgr->AddWindow(_T("child"), child);
        }
    }

    auto iret = mgr->Run();
    mgr->Uninit();

    return iret;
}